package cn.com.idmy.base.util;


import org.jetbrains.annotations.NotNull;

public class MaskUtil {
    public static @NotNull String mask(@NotNull String str, int front, int back) {
        if (front < 0 || back < 0 || front >= str.length() || front >= str.length() - back) {
            return str;
        } else {
            int actualEnd = str.length() - back;
            String maskedPart = "*".repeat(actualEnd - front);
            return str.substring(0, front) + maskedPart + str.substring(actualEnd);
        }
    }
}
